

// @ts-ignore
interface AniConfig{
    url:string;
    tokenUrl:string;
    header?:object;
    loading?:boolean;
    timeout?:number;
    errCode?:[];
}
const baseConfig={
    loading:false,
    timeout:15000,
    header:{
        contentType:"application/json"
    }
}

class AniReq{
    private config: AniConfig;
    private reqMethod
    constructor(config:AniConfig) {
        this.config=Object.assign(baseConfig,config)
    }

    setHeader(header:object){
        this.config.header=header
    }
    get(data){
        return this.request({
            method:'GET',
            data
        })
    }
    post(data){
        return this.request({
            method:"POST",
            data
        })
    }
    put(data){
        return this.request({
            method:"PUT",
            data
        })
    }
    delete(data){
        return this.request({
            method:"DELETE",
            data
        })
    }
    private async request(options){

        const {header,timeout}=this.config

        function req(){
            return new Promise((resolve) => {

                this.reqMethod=setTimeout(_=>{
                    resolve(options)
                },1000)


                // @ts-ignore
                // wx.request({
                //     header,
                //     timeout,
                //     success(res){
                //         resolve(res)
                //     },
                //     fail(err){
                //         resolve(false)
                //     },
                //     complete(){
                //
                //     }
                // })
            })
        }

        const res=await req();
        // @ts-ignore
        if(res.code===403){

        }
    }


}
const myReq=new AniReq({
    url:'http://localhost:8080',
    tokenUrl:'getToken'
})
async function init(){
    const myRes=myReq.get({

    })
}